package com.toolkit.common;

import com.toolkit.enumData.ExceptionCodeMsg;
import lombok.Data;

@Data
public class CommonRespBean <T>{
    //服务端返回的错误码
    private int code;
    //服务端返回的错误信息
    private String msg;
    //我们服务端返回的数据
    private T data;
    private CommonRespBean(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private CommonRespBean(int code, T data){
        this.code = code;
        this.data = data;
    }

    private CommonRespBean(int code){
        this.code = code;
    }


    public static <T> CommonRespBean success(T data,String message){
        CommonRespBean resp = new CommonRespBean(200, message, data);
        return resp;
    }

    /**
     * 操作成功
     * @param data
     * @return
     * @param <T>
     */
    public static <T> CommonRespBean success(T data){
        CommonRespBean resp = new CommonRespBean(200, data);
        return resp;
    }

    /**
     * 操作成功
     * @return
     * @param <T>
     */
    public static <T> CommonRespBean success(){
        CommonRespBean resp = new CommonRespBean(200);
        return resp;
    }

    public static <T> CommonRespBean success(T data, ExceptionCodeMsg exceptionCodeMsg){
        CommonRespBean resp = new CommonRespBean(exceptionCodeMsg.getCode(), exceptionCodeMsg.getMsg(), data);
        return resp;
    }
    public static <T> CommonRespBean error(ExceptionCodeMsg appExceptionCodeMsg){
        CommonRespBean resp = new CommonRespBean(appExceptionCodeMsg.getCode(), appExceptionCodeMsg.getMsg(), null);
        return resp;
    }
    public static <T> CommonRespBean error(int code, String msg){
        CommonRespBean resp = new CommonRespBean(code,msg, null);
        return resp;
    }
}
